package com.atguigu.lease.common.Exception;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    /*将返回值序列化为Http响应体*/
    @ResponseBody
    public Result exceptionHanler(Exception e) {
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(LeaseException.class)
    @ResponseBody
    public Result LeaseExceptionHandler(LeaseException e) {
        return Result.handler(e.getMessage(), e.getCode());
    }
}
